package com.miao.elm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miao.elm.dao.UserDao;
import com.miao.elm.entity.UserEntity;
import com.miao.elm.service.UserService;
import com.miao.elm.to.UserTo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Override
    public UserEntity getUserByIdByPass(String userId, String password) {
        UserEntity userEntity = this.baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("user_id", userId).eq("password", password));
        System.out.println(userEntity);
        return userEntity;
    }

    @Override
    public int getUserById(String userId) {
        return this.baseMapper.selectCount(new QueryWrapper<UserEntity>().eq("user_id", userId));
    }

    @Override
    public int saveUser(UserTo userTo) {
        System.out.println(userTo);
        UserEntity userEntity = new UserEntity();
        BeanUtils.copyProperties(userTo, userEntity);
        System.out.println(userEntity);
        return this.baseMapper.insert(userEntity);
    }
}